package com.taoyibao.hongcanting.ui.mine.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.activity.BaseActivityNoSlidePresenter;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.event.EventCurrentPage;
import com.taoyibao.hongcanting.ui.home.delegate.PaymentResultDelegate;

import org.greenrobot.eventbus.EventBus;

/**
 * @author TangAnna
 * @description: 支付结果
 * @date :${DATA} 16:35
 */
public class PaymentResultActivity extends BaseActivityNoSlidePresenter<PaymentResultDelegate> implements View.OnClickListener {
    private String mOrderId;
    private String memberId;

    @Override
    protected Class<PaymentResultDelegate> getDelegateClass() {
        return PaymentResultDelegate.class;
    }

    /**
     * @param context
     * @param way       支付方式
     * @param payAmount 支付金额
     * @param orederId  订单ID
     */
    public static void open(Context context, int way, double payAmount, String orederId, String memberId) {
        Intent intent = new Intent(context, PaymentResultActivity.class);
        intent.putExtra(CodeConstant.PAY_WAY, way);
        intent.putExtra(CodeConstant.AMOUNT, payAmount);
        intent.putExtra(CodeConstant.ORDER_ID, orederId);
        intent.putExtra(CodeConstant.MEMBER_ID, memberId);
        context.startActivity(intent);
    }

    @Override
    protected void bindEvenListener() {
        super.bindEvenListener();
        mOrderId = getIntent().getStringExtra(CodeConstant.ORDER_ID);
        memberId = getIntent().getStringExtra(CodeConstant.MEMBER_ID);
        int way = getIntent().getIntExtra(CodeConstant.PAY_WAY, 0);
        double payAmount = getIntent().getDoubleExtra(CodeConstant.AMOUNT, 0);
        viewDelegate.setData(way, payAmount);
        viewDelegate.get(R.id.tv_payResult_orderDetail).setOnClickListener(this);
        viewDelegate.get(R.id.tv_payResult_home).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_payResult_orderDetail://订单详情
                OrderDetailActivity.open(this, mOrderId, memberId,CodeConstant.ORDER_STATUS_COMPLETED);
                break;
            case R.id.tv_payResult_home://返回首页
                sendManinEvent();
                break;
        }
        finish();
    }

    /**
     * 发送消息给MainActivity页面
     */
    public void sendManinEvent() {
        EventCurrentPage eventCurrentPage = new EventCurrentPage();
        eventCurrentPage.mCurrentPage = 0;
        eventCurrentPage.target = "MainActivity";
        EventBus.getDefault().post(eventCurrentPage);
    }
}
